home *** CD-ROM | disk | FTP | other *** search
- /* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
- Object List
-
- Defines an object that holds a list of other objects and uses the
- List Manager to display them.
- |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| */
-
- #ifndef CLASS_LISTOBJ
- #include "CListObj.h"
- #endif
-
- /* |||||||||||||||||||| */
- void CListObj::IList ( Rect *viewR, int cellHeight, Boolean hasScrollBar,
- int selectMethod, WindowPtr theWin )
- {
- Rect dataBounds, viewBounds;
- Point cellSize;
- Handle fakeDefProc;
- int jmpInstruction;
- long jmpAddress;
-
- /*** create the "fake" defproc handle and put a jump to our code in it */
- jmpInstruction = 0x4EF9;
- jmpAddress = (long) ListFunction;
- fakeDefProc = GetResource( 'LDEF', MYPROCID );
- HLock ( fakeDefProc );
- BlockMove ( &jmpInstruction, *fakeDefProc, sizeof ( int ) );
- BlockMove ( &jmpAddress, *fakeDefProc + 2, sizeof ( long ) );
- HUnlock ( fakeDefProc );
-
- /*** initialize the list object, set up the corresponding list manager object */
- theList = NULL;
- viewRect = viewBounds = *viewR;
- drawIt = true;
- SetRect ( &dataBounds, 0, 0, 1, 0 );
- cellSize.h = viewR->right - viewR->left;
- cellSize.v = cellHeight;
- viewBounds.right -= 15;
- theList = LNew ( &viewBounds, &dataBounds, cellSize, MYPROCID, theWin, true, false, false, hasScrollBar );
- (*theList)->selFlags = (SignedByte) selectMethod;
- (*theList)->refCon = (long) this;
- }
-
- /* |||||||||||||||||||| */
- void CListObj::Dispose ( void )
- {
- /*** dispose of the list, but not it's contents */
- LDispose ( theList );
- inherited::Dispose ( );
- }
-
- /* |||||||||||||||||||| */
- Boolean CListObj::MouseInList ( Point thePoint, int modifiers )
- {
- /*** process a mouse click in the list by calling the toolbox List Manager */
- if ( PtInRect ( thePoint, &viewRect ) && drawIt ) {
- LClick ( thePoint, modifiers, theList );
- return true; /* return true if the mouse point WAS in the list */
- }
- return false; /* return false if it was a miss */
- }
-
- /* |||||||||||||||||||| */
- void CListObj::UpdateList ( RgnHandle updateRgn )
- {
- /*** process an update event (only if drawing is turned on) */
- if ( drawIt ) LUpdate ( updateRgn, theList );
- }
-
- /* |||||||||||||||||||| */
- void CListObj::ActivateList ( Boolean activate )
- {
- /*** process an activate event */
- LActivate ( activate, theList );
- }
-
- /* |||||||||||||||||||| */
- void CListObj::DrawingOn ( Boolean drawing )
- {
- /*** turn drawing on or off */
- drawIt = drawing;
- LDoDraw ( drawing, theList );
- }
-
- /* |||||||||||||||||||| */
- void CListObj::Scroll ( int amount )
- {
- /*** scroll the list (positive numbers scroll up) */
- LScroll ( 0, amount, theList );
- }
-
- /* |||||||||||||||||||| */
- int CListObj::NumObjs ( void )
- {
- /*** return the number of objects in the list */
- return ( (*theList)->dataBounds.bottom );
- }
-
- /* |||||||||||||||||||| */
- void CListObj::Add ( CItemObj *theObject )
- {
- int rowNum;
- long value;
- Cell theCell;
-
- /*** add an item to the bottom of the list */
- rowNum = LAddRow ( 1, 32760, theList );
- value = (long) theObject;
- theCell.h = 0;
- theCell.v = rowNum;
- LSetCell ( &value, sizeof ( long ), theCell, theList );
- }
-
- /* |||||||||||||||||||| */
- void CListObj::Remove ( CItemObj *theObject )
- {
- int nRows, len;
- long value;
- Cell theCell;
-
- /*** delete the object from the list, if it's in it (doesn't delete the object) */
- len = sizeof ( long );
- nRows = NumObjs ( );
- for ( theCell.h = 0, theCell.v = 0; theCell.v < nRows; ++theCell.v ) {
- LGetCell ( &value, &len, theCell, theList );
- if ( value == (long) theObject ) {
- LDelRow ( 1, theCell.v, theList );
- return;
- }
- }
- }
-
- /* |||||||||||||||||||| */
- void CListObj::ForEach ( VoidFunc doThis )
- {
- int nRows, len;
- long value;
- Cell theCell;
- CItemObj *theObject;
-
- /*** call the doThis function, passing each object in the list */
- len = sizeof ( long );
- nRows = NumObjs ( );
- for ( theCell.h = 0, theCell.v = 0; theCell.v < nRows; ++theCell.v ) {
- LGetCell ( &value, &len, theCell, theList );
- theObject = (CItemObj *) value;
- doThis ( theObject );
- }
- }
-
- /* |||||||||||||||||||| */
- void CListObj::ForEachSelected ( VoidFunc doThis )
- {
- int nRows, len;
- long value;
- Cell theCell;
- CItemObj *theObject;
-
- /*** call the VoidFunc, passing each selected object in the list */
- len = sizeof ( long );
- nRows = NumObjs ( );
- theCell.h = theCell.v = 0;
- while ( LGetSelect ( true, &theCell, theList ) ) {
- LGetCell ( &value, &len, theCell, theList );
- theObject = (CItemObj *) value;
- doThis ( theObject );
- ++theCell.v;
- }
- }
-
- /* |||||||||||||||||||| */
- void CListObj::SelectNone ( void )
- {
- int nRows;
- long value;
- Cell theCell;
- CItemObj *theObject;
-
- /*** de-select all items */
- nRows = NumObjs ( );
- theCell.h = theCell.v = 0;
- while ( LGetSelect ( true, &theCell, theList ) ) {
- LSetSelect ( false, theCell, theList );
- ++theCell.v;
- }
- }
-
- /* |||||||||||||||||||| */
- Boolean CListObj::AnySelected ( void )
- {
- Cell theCell;
-
- /*** return true if any item is selected */
- theCell.h = theCell.v = 0;
- return ( LGetSelect ( true, &theCell, theList ) );
- }
-
- /* |||||||||||||||||||| */
- CItemObj * CListObj::FirstThat ( BooleanFunc test )
- {
- int nRows, len;
- long value;
- Cell theCell;
- CItemObj *theObject;
-
- /*** return the first item that passes the test in function test */
- len = sizeof ( long );
- nRows = NumObjs ( );
- for ( theCell.h = 0, theCell.v = 0; theCell.v < nRows; ++theCell.v ) {
- LGetCell ( &value, &len, theCell, theList );
- theObject = (CItemObj *) value;
- if ( test ( theObject ) ) return ( theObject );
- }
- return ( NULL );
- }
-
- /* |||||||||||||||||||| */
- CItemObj * CListObj::GetIndObject ( int n )
- {
- int len;
- long value;
- Cell theCell;
- CItemObj *theObject;
-
- /*** return the nth object in the list (list manager is 0 based, ListObj is 1 based) */
- --n;
- if ( (n < NumObjs ( )) && (n >= 0) ) {
- theCell.h = 0;
- theCell.v = n;
- len = sizeof ( long );
- LGetCell ( &value, &len, theCell, theList );
- theObject = (CItemObj *) value;
- return ( theObject );
- }
- return ( NULL );
- }
-
- /* ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||*/
- pascal void ListFunction ( int lMessage, Boolean lSelect, Rect *lRect, Cell lCell,
- int lDataOffset, int lDataLen, ListHandle lHandle )
- {
- CItemObj *item;
- long *theData;
-
- /*** dispatch a message sent to a list by the list manager to the object it goes with */
- switch ( lMessage ) {
- case lInitMsg:
- break;
- case lDrawMsg:
- if ( lDataLen > 0 ) {
- theData = (long *) **(*lHandle)->cells;
- theData += lDataOffset/4;
- item = (CItemObj *) *theData;
- item->DrawItem ( lSelect, lRect );
- }
- break;
- case lHiliteMsg:
- if ( lDataLen > 0 ) {
- theData = (long *) **(*lHandle)->cells;
- theData += lDataOffset/4;
- item = (CItemObj *) *theData;
- item->DrawItem ( lSelect, lRect );
- }
- break;
- case lCloseMsg:
- break;
- }
- }
-